package id.net.iconpln.bb.server;

import id.net.iconpln.bb.client.model.BbEntryJadwalBean;
import id.net.iconpln.bb.client.model.BbEntryPasokanBean;
import id.net.iconpln.bb.client.model.BbEntryTransportirBean;
import id.net.iconpln.bb.client.model.BbMasterPemasokBean;
import id.net.iconpln.bb.client.model.BbMstPembangkitBean;
import id.net.iconpln.bb.client.model.BbMstSurveyorBean;
import id.net.iconpln.bb.client.model.BeanMasterModul;
import id.net.iconpln.bb.client.model.BeanModelMasterBb;
import id.net.iconpln.bb.client.model.BeanModelPerencanaanBb;
import id.net.iconpln.bb.client.model.Customer;
import id.net.iconpln.bb.client.model.PageBbRakorPKSBean;
import id.net.iconpln.bb.client.model.PbBean;
import id.net.iconpln.bb.client.model.UserBean;
import id.net.iconpln.bb.client.service.BatubaraService;
import id.net.iconpln.bb.server.model.persistence.MasterAllMembers;
import id.net.iconpln.bb.server.model.persistence.MasterJadwal;
import id.net.iconpln.bb.server.model.persistence.MasterModul;
import id.net.iconpln.bb.server.model.persistence.MasterPasokan;
import id.net.iconpln.bb.server.model.persistence.MasterPemasok;
import id.net.iconpln.bb.server.model.persistence.MasterPembangkit;
import id.net.iconpln.bb.server.model.persistence.MasterSurveyor;
import id.net.iconpln.bb.server.model.persistence.MasterTransportir;
import id.net.iconpln.bb.server.model.persistence.ModelPerencanaaBb;
import id.net.iconpln.bb.server.model.persistence.RakorPKS;
import id.net.iconpln.bb.server.service.BbServices;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gwtrpcspring.RemoteServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@Repository("batuBaraService")
public class BatubaraServiceImpl extends RemoteServiceServlet implements
		BatubaraService {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3694102031010378417L;
	private String tahunblnDash; // = "null;
	private static final Log log = LogFactory.getLog(BatubaraServiceImpl.class);


	@Autowired
	private BbServices bbService;

public List<UserBean> ipBrowser() {
		
		List<UserBean> lMap = new ArrayList<UserBean>();
	
		try {
			UserBean g = new UserBean();
//			g.setId_unit(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("id_unit").toString());
//			g.setJenis_unit(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("jenis_unit").toString());
//			g.setNama_unit(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("nama_unit").toString());
//			g.setUser(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("user").toString());
//			g.setModule(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("module").toString());
//			g.setLeveluser(RemoteServiceUtil.getThreadLocalRequest().getSession().getAttribute("leveluser").toString());
			g.setId_unit("1");
			g.setJenis_unit("3");
			g.setNama_unit("PKS.BER");
			g.setUser("PEMASOKBER");
			g.setModule("TRANSPORT");
			g.setLeveluser("PEMASOK");
			lMap.add(g);

			System.out.println("module: " + lMap.get(0).getModule().toString());
			System.out.println("id unit: " + lMap.get(0).getId_unit().toString());
			System.out.println("nama Unit: " + lMap.get(0).getNama_unit().toString());
			System.out.println("user: " + lMap.get(0).getUser().toString());
			System.out.println("Jenis Unit: " + lMap.get(0).getJenis_unit().toString());
			System.out.println("Level User: " + lMap.get(0).getLeveluser().toString());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
//		
		return lMap;
		
	}

	public HttpSession getHttpSession(){
		return RemoteServiceUtil.getThreadLocalRequest().getSession();
	}	
	public List<PbBean> GetPasangBaru(String unitup, String trx) {
		// TODO Auto-generated method stub

		List<PbBean> lMap = new ArrayList<PbBean>();
		// Map map = nesw HashMap();
		try {
			PbBean g = new PbBean();
			g.setUnitup(unitup.substring(2, 5));
			g.setJenismutasi("PB");
			lMap.add(g);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		System.out.println(lMap.get(0).getUnitup());
		return lMap;
	}

	public String GetPbDetail(String unitup, String trx, Date tglawal,
			Date tglakhir) {

		String apl = unitup.substring(2, 5);
		return apl;
	}


	public List<Customer> getCustomers() {
		List<Customer> customers = new ArrayList<Customer>();
		customers.add(new Customer("Darrell", "darrell@foo.com", 1));
		customers.add(new Customer("Maro", "maro@foo.com", 2));
		customers.add(new Customer("Alec", "alec@foo.com", 3));
		customers.add(new Customer("Lia", "lia@foo.com", 4));
		return customers;
	}

//	public void getSlidePage(){
//		try{
////			List<LogPage> pg = new ArrayList<LogPage>();
//			List<LogPage> pg = masterService.getLogPageAll();
//
//			System.out.println("call function getSlidepage total: " + pg.size());
//			
//			for(int i=0; i < pg.size(); i++){
//				System.out.println(pg.get(i).getNamapage().toString()+" " + pg.get(i).getNamaupi().toString());
//			}
//		}catch(Exception e){
//			e.getMessage();
//		}
//	}

	public String setDashThnBln(String tahunbln) {
		// TODO Auto-generated method stub
		
		tahunblnDash = tahunbln;
		System.out.println("Tahun bulan setDashThnBln : " + tahunblnDash);
		String t = tahunblnDash;
		return "tahubln dash :" +t;
	}

	@Override
	public List<BeanMasterModul> getMasterModul() {
		// TODO Auto-generated method stub
		List<BeanMasterModul> gb = new ArrayList<BeanMasterModul>();
		try {
			List<MasterModul> gs = bbService.getMasterModul();
		
			System.out.println("total : " + gs.size());
			
			for (int i = 0; i < gs.size(); i++) {
				BeanMasterModul u = new BeanMasterModul();
//				u.setId(i + 1);
				u.setId_module(gs.get(i).getId_module().toString());
				u.setKeterangan_modul(gs.get(i).getKeterangan_modul().toString());
				gb.add(u);
				System.out.println("id modul : " + gs.get(i).getId_module().toString() +  
								   "ket modul : " + gs.get(i).getKeterangan_modul().toString()); 
			}				
		} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return gb;
	}

	@Override
	public List<BeanModelMasterBb> getListMasterBb(String codeMaster) {
		// TODO Auto-generated method stub
		System.out.println("masuk service");
		List<BeanModelMasterBb> aa = new ArrayList<BeanModelMasterBb>();
		
		List<MasterAllMembers> bb = bbService.getListMasterBb(codeMaster);
		System.out.println("Total : " + bb.size());
		try {
			if (codeMaster.equals("KIT")){
				for (int i = 0; i < bb.size(); i++) {
					System.out.println("kit di service");
					BeanModelMasterBb u = new BeanModelMasterBb();
					u.setId_pltu(bb.get(i).getId_pltu().toString());
					u.setNama_pembangkit(bb.get(i).getNama_pembangkit());
					u.setNama_pic(bb.get(i).getNama_pic());
					u.setAlamat(bb.get(i).getAlamat());
					u.setKepemilikan(bb.get(i).getKepemilikan());
					u.setWilayah(bb.get(i).getWilayah().toString());
					u.setJenis_pembangkit(bb.get(i).getJenis_pembangkit());
					u.setTelp(bb.get(i).getTelp());
					u.setDaya_terpasang(bb.get(i).getDaya_terpasang());
					u.setSfc(bb.get(i).getSfc());
					u.setCapacity_factor(bb.get(i).getCapacity_factor());
					u.setHeat_rate(bb.get(i).getHeat_rate());
					
					aa.add(u);
				}
			}else if (codeMaster.equals("SURVEYOR")){
				for (int i = 0; i < bb.size(); i++) {
					BeanModelMasterBb u = new BeanModelMasterBb();
					u.setId_surveyor(bb.get(i).getId_surveyor().toString());
					u.setNama_surveyor(bb.get(i).getNama_surveyor().toString());
					u.setNo_kerjasama(bb.get(i).getNo_kerjasama().toString());
					u.setTanggal(bb.get(i).getTanggal().toString().toString());
					u.setTelp(bb.get(i).getTelp().toString());
					u.setAlamat(bb.get(i).getAlamat().toString());
					u.setPic(bb.get(i).getPic().toString());
					u.setKeterangan(bb.get(i).getKeterangan().toString());
					u.setNo_kontrak(bb.get(i).getNo_kontrak().toString());
					aa.add(u);
				}
			}else if (codeMaster.equals("TRANSPORTIR")){
				for (int i = 0; i < bb.size(); i++) {
					BeanModelMasterBb u = new BeanModelMasterBb();
					u.setId_transportir(bb.get(i).getId_transportir().toString());
					u.setNama_transportir(bb.get(i).getNama_transportir().toString());
					System.out.println("nama transportir: " + bb.get(i).getNama_transportir().toString());
					u.setAlamat(bb.get(i).getAlamat().toString());
					u.setTelp(bb.get(i).getTelp().toString());
					u.setPic(bb.get(i).getPic().toString());
					u.setNama_transport(bb.get(i).getNama_transport().toString());
					u.setJenis_transport(bb.get(i).getJenis_transport().toString());
					u.setKode_transport(bb.get(i).getKode_transport().toString());
					u.setJumlah_kapal(bb.get(i).getJumlah_kapal().toString().toString());
					u.setSpec_kapal(bb.get(i).getSpec_kapal().toString());
					aa.add(u);
				}
			}else if (codeMaster.equals("PEMASOK")){
				System.out.println("masuk pemasok");
				for (int i = 0; i < bb.size(); i++) {
					BeanModelMasterBb u = new BeanModelMasterBb();
					u.setId_pemasok(bb.get(i).getId_pemasok().toString());
					System.out.println("id pemasok: " + bb.get(i).getId_pemasok().toString());
					u.setPemasok(bb.get(i).getPemasok().toString());
					System.out.println("pemasok: " + bb.get(i).getPemasok().toString());
					u.setAlamat(bb.get(i).getAlamat().toString());
					u.setPic_presdir(bb.get(i).getPic_presdir().toString());
					u.setPic_presdir_hp(bb.get(i).getPic_presdir_hp().toString());
					u.setPic_dir_marketing(bb.get(i).getPic_dir_marketing().toString());
					u.setPic_dir_marketing_hp(bb.get(i).getPic_dir_marketing_hp().toString());
					u.setPic_man_opr(bb.get(i).getPic_man_opr().toString());
					u.setPic_man_opr_hp(bb.get(i).getPic_man_opr_hp().toString());
					u.setStatus_pemasok(bb.get(i).getStatus_pemasok().toString());
					u.setNama_tambang(bb.get(i).getNama_tambang().toString());
					u.setProduksi(bb.get(i).getProduksi().toString());
					u.setLoading_port(bb.get(i).getLoading_port().toString());
					u.setFasilitas_loading(bb.get(i).getFasilitas_loading().toString());
					u.setJarak_hauling(bb.get(i).getJarak_hauling().toString());
					u.setFlag_blacklist(bb.get(i).getFlag_blacklist().toString());
					u.setStatus_aktif(bb.get(i).getStatus_aktif().toString());
					u.setKeterangan(bb.get(i).getKeterangan().toString());
					u.setId_pusat(bb.get(i).getId_pusat().toString());
					u.setStatus(bb.get(i).getStatus().toString());
					u.setTelp(bb.get(i).getTelp().toString());
					u.setFax(bb.get(i).getFax().toString());
					u.setEmail(bb.get(i).getEmail().toString());
					
					aa.add(u);
				}
			}
						
		} catch (Exception e) {
		// TODO: handle exception
			e.getMessage();
		}
		return aa;		
	}
	@Override
	public String logout() {
		// TODO Auto-generated method stub
//		HttpServletRequest re = this.getThreadLocalRequest();
		RemoteServiceUtil.getThreadLocalRequest().getSession().removeAttribute("module");
//		RemoteServiceUtil.getThreadLocalRequest().getSession().setAttribute("module", null);
		return "Sukess logout";
	}
	@Override
	public List<BeanModelPerencanaanBb> getListPerencanaanBb(String id_pltu) {
		// TODO Auto-generated method stub
		List<BeanModelPerencanaanBb> aa = new ArrayList<BeanModelPerencanaanBb>();
    	
		List<ModelPerencanaaBb> bb = new ArrayList<ModelPerencanaaBb>();
		bb = bbService.getListPerencanaanBb(id_pltu);
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BeanModelPerencanaanBb u = new BeanModelPerencanaanBb();
				u.setId_plan(bb.get(i).getId_plan().toString());
				u.setId_uraian(bb.get(i).getId_uraian().toString());
				u.setId_unit(bb.get(i).getId_unit().toString());
				u.setId_kategori(bb.get(i).getId_kategori().toString());
				u.setId_pltu(bb.get(i).getId_pltu().toString());
				u.setId_instansi(bb.get(i).getId_instansi().toString());
				u.setSatuan(bb.get(i).getSatuan());
				u.setJan(bb.get(i).getJan().toString());
				u.setFeb(bb.get(i).getFeb().toString());
				u.setMar(bb.get(i).getMar().toString());
				u.setApr(bb.get(i).getApr().toString());
				u.setMei(bb.get(i).getMei().toString());
				u.setJun(bb.get(i).getJun().toString());
				u.setJul(bb.get(i).getJul().toString());
				u.setAgt(bb.get(i).getAgt().toString());
				u.setSept(bb.get(i).getSept().toString());
				u.setOkt(bb.get(i).getOkt().toString());
				u.setNop(bb.get(i).getNop().toString());
				u.setDes(bb.get(i).getDes().toString());
				u.setTahun(bb.get(i).getTahun().toString());
				u.setTriw_satu(bb.get(i).getTriw_satu().toString());
				u.setTriw_dua(bb.get(i).getTriw_dua().toString());
				u.setTriw_tiga(bb.get(i).getTriw_tiga().toString());
				u.setTriw_empat(bb.get(i).getTriw_empat().toString());
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
  }
	@Override
	public List<BbMstPembangkitBean> getkitall() {
		// TODO Auto-generated method stub
		List<BbMstPembangkitBean> aa = new ArrayList<BbMstPembangkitBean>();
    	
		List<MasterPembangkit> bb = new ArrayList<MasterPembangkit>();
		bb = bbService.getkitall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BbMstPembangkitBean u = new BbMstPembangkitBean();
				u.setId_pltu(bb.get(i).getId_pltu().toString());
				u.setNama_pembangkit(bb.get(i).getNama_pembangkit());
				u.setNama_pic(bb.get(i).getNama_pic());
				u.setAlamat(bb.get(i).getAlamat());
				u.setKepemilikan(bb.get(i).getKepemilikan());
				u.setLatitude(bb.get(i).getLatitude().toString());
				u.setLongitude(bb.get(i).getLongitude().toString());
				u.setWilayah(bb.get(i).getWilayah().toString());
				u.setJenis_pembangkit(bb.get(i).getJenis_pembangkit());
				u.setTelp(bb.get(i).getTelp());
				u.setDaya_terpasang(bb.get(i).getDaya_terpasang());
				u.setSfc(bb.get(i).getSfc());
				u.setCapacity_factor(bb.get(i).getCapacity_factor());
				u.setHeat_rate(bb.get(i).getHeat_rate());
				u.setCreateby(bb.get(i).getCreateby());
				u.setCreatedate(bb.get(i).getCreatedate().toLocaleString());
				u.setUpdateby(bb.get(i).getUpdateby());
				u.setUpdatedate(bb.get(i).getUpdatedate().toLocaleString());
				u.setApp_access(bb.get(i).getApp_access());
				
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<BbMasterPemasokBean> getpemasokall() {
		// TODO Auto-generated method stub
		List<BbMasterPemasokBean> aa = new ArrayList<BbMasterPemasokBean>();
    	
		List<MasterPemasok> bb = new ArrayList<MasterPemasok>();
		bb = bbService.getpemasokall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BbMasterPemasokBean u = new BbMasterPemasokBean();
				u.setId_pjbb(bb.get(i).getId_pjbb().toString());
				u.setId_jenis_kontrak(bb.get(i).getId_jenis_kontrak().toString());
				u.setId_pemasok(bb.get(i).getId_pemasok().toString());
				u.setId_pltu(bb.get(i).getId_pltu().toString());
				u.setTahun(bb.get(i).getTahun().toString());
				u.setNo_pjbb(bb.get(i).getNo_pjbb());
				u.setTgl_pjbb(bb.get(i).getTgl_pjbb().toString());
				u.setLot(bb.get(i).getLot().toString());
				u.setKeb_pertahun(bb.get(i).getKeb_pertahun().toString());
				u.setVol_pjbb(bb.get(i).getVol_pjbb().toString());
				u.setVol_pjbb_tahun(bb.get(i).getVol_pjbb_tahun().toString());
				u.setHarga_rp_ton(bb.get(i).getHarga_rp_ton().toString());
				u.setHarga_penyesuaian(bb.get(i).getHarga_penyesuaian().toString());
				u.setRp_nilai_kontrak(bb.get(i).getRp_nilai_kontrak().toString());
				u.setKalori(bb.get(i).getKalori().toString());
				u.setMasa_berlaku(bb.get(i).getMasa_berlaku());
				u.setKeterangan(bb.get(i).getKeterangan());
				u.setJenis_pengiriman(bb.get(i).getJenis_pengiriman());
				u.setJaminan_bank(bb.get(i).getJaminan_bank());
				
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<BbEntryJadwalBean> getjadwalall() {
		// TODO Auto-generated method stub
		List<BbEntryJadwalBean> aa = new ArrayList<BbEntryJadwalBean>();
    	
		List<MasterJadwal> bb = new ArrayList<MasterJadwal>();
		bb = bbService.getjadwalall();
		
		for (int i = 0; i < bb.size(); i++) {
			BbEntryJadwalBean u = new BbEntryJadwalBean();
			u.setId_jadwal(bb.get(i).getId_jadwal().toString());
			System.out.println("id jadwal: " + bb.get(i).getId_jadwal().toString());
			u.setId_pasokan(bb.get(i).getId_pasokan().toString());
			System.out.println("id pasokan: " + bb.get(i).getId_pasokan().toString());
			u.setId_pemasok(bb.get(i).getId_pemasok().toString());
			System.out.println("id pemasok: " + bb.get(i).getId_pemasok().toString());
			u.setId_transportir(bb.get(i).getId_transportir().toString());
			System.out.println("id transportir: " + bb.get(i).getId_transportir().toString());
			u.setId_bahan_bakar(bb.get(i).getId_bahan_bakar().toString());
			System.out.println("id bahan bakar: " + bb.get(i).getId_bahan_bakar().toString());
			u.setId_pltu(bb.get(i).getId_pltu().toString());
			System.out.println("id pltu: " + bb.get(i).getId_pltu().toString());
			u.setId_rakor(bb.get(i).getId_rakor().toString());
			System.out.println("id rakor: " + bb.get(i).getId_rakor().toString());
			u.setTgl_ta(bb.get(i).getTgl_ta().toString());
			System.out.println("id tgl ta: " + bb.get(i).getTgl_ta().toString());
			u.setTgl_td(bb.get(i).getTgl_td().toString());
			System.out.println("id tgl td: " + bb.get(i).getTgl_td().toString());
			u.setVolume(bb.get(i).getVolume().toString());
			System.out.println("id volume: " + bb.get(i).getVolume().toString());
//			u.setCreateby(bb.get(i).getCreateby().toString());
//			System.out.println("id create by: " + bb.get(i).getCreateby().toString());
//			u.setCreatedate(bb.get(i).getCreatedate().toString());
//			System.out.println("id create date: " + bb.get(i).getCreatedate().toString());
//			u.setUpdateby(bb.get(i).getUpdateby().toString());
//			System.out.println("id update by: " + bb.get(i).getUpdateby().toString());
//			u.setUpdatedate(bb.get(i).getUpdatedate().toString());
//			System.out.println("id update date: " + bb.get(i).getUpdatedate().toString());
//			u.setApp_access(bb.get(i).getApp_access().toString());
//			System.out.println("id app: " + bb.get(i).getApp_access().toString());
			
			aa.add(u);
		}
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<PageBbRakorPKSBean> getrakorall() {
		// TODO Auto-generated method stub
		List<PageBbRakorPKSBean> aa = new ArrayList<PageBbRakorPKSBean>();
    	
		List<RakorPKS> bb = new ArrayList<RakorPKS>();
		bb = bbService.getrakorall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				PageBbRakorPKSBean u = new PageBbRakorPKSBean();
				u.setId_rakor(bb.get(i).getId_rakor().toString());
				u.setTanggal(bb.get(i).getTanggal());
				u.setTempat(bb.get(i).getTempat().toString());
				u.setAlamat(bb.get(i).getAlamat().toString());
				u.setKeterangan(bb.get(i).getKeterangan().toString());
				u.setAgenda(bb.get(i).getAgenda().toString());
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<BbMstSurveyorBean> getsurveyorall() {
		// TODO Auto-generated method stub
		List<BbMstSurveyorBean> aa = new ArrayList<BbMstSurveyorBean>();
    	
		List<MasterSurveyor> bb = new ArrayList<MasterSurveyor>();
		bb = bbService.getsurveyorall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BbMstSurveyorBean u = new BbMstSurveyorBean();
				u.setId_surveyor(bb.get(i).getId_surveyor().toString());
				u.setNama_surveyor(bb.get(i).getNama_surveyor());
				u.setNo_kerjasama(bb.get(i).getNo_kerjasama());
				u.setTanggal(bb.get(i).getTanggal().toString());
				u.setTelp(bb.get(i).getTelp());
				u.setAlamat(bb.get(i).getAlamat());
				u.setPic(bb.get(i).getPic());
				u.setKeterangan(bb.get(i).getKeterangan());
				u.setNo_kontrak(bb.get(i).getNo_kontrak());
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<BbEntryTransportirBean> gettransall() {
		// TODO Auto-generated method stub
		List<BbEntryTransportirBean> aa = new ArrayList<BbEntryTransportirBean>();
    	
		List<MasterTransportir> bb = new ArrayList<MasterTransportir>();
		bb = bbService.gettransall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BbEntryTransportirBean u = new BbEntryTransportirBean();
				u.setId_transportir(bb.get(i).getId_transportir().toString());
				u.setNama_transportir(bb.get(i).getNama_transportir());
				u.setAlamat(bb.get(i).getAlamat());
				u.setTelp(bb.get(i).getTelp());
				u.setPic(bb.get(i).getPic());
				u.setNama_transport(bb.get(i).getNama_transport());
				u.setJenis_transport(bb.get(i).getJenis_transport());
				u.setKode_transport(bb.get(i).getKode_transport());
				u.setJumlah_kapal(bb.get(i).getJumlah_kapal().toString());
				u.setSpec_kapal(bb.get(i).getSpec_kapal());
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	@Override
	public List<BbEntryPasokanBean> getpasokanall() {
		// TODO Auto-generated method stub
		List<BbEntryPasokanBean> aa = new ArrayList<BbEntryPasokanBean>();
    	
		List<MasterPasokan> bb = new ArrayList<MasterPasokan>();
		bb = bbService.getpasokanall();
		
		try {
			
			System.out.println("total : " + bb.size());
			log.info("Total: " + bb.size()); 
			
			for (int i = 0; i < bb.size(); i++) {
				BbEntryPasokanBean u = new BbEntryPasokanBean();
				u.setId_pasokan(bb.get(i).getId_pasokan().toString());
				u.setId_pemasok(bb.get(i).getId_pemasok().toString());
				u.setId_pjbb(bb.get(i).getId_pjbb().toString());
				u.setId_pltu(bb.get(i).getId_pltu().toString());
				u.setId_rakor(bb.get(i).getId_rakor().toString());
				u.setVolume(bb.get(i).getVolume().toString());
				u.setSatuan(bb.get(i).getSatuan().toString());
				u.setTgl_eta(bb.get(i).getTgl_eta().toString());
				u.setTgl_etd(bb.get(i).getTgl_etd().toString());
				u.setBulan_tahun(bb.get(i).getBulan_tahun().toString());
				u.setKeterangan(bb.get(i).getKeterangan().toString());
				u.setTgl_bongkar(bb.get(i).getTgl_bongkar().toString());
				aa.add(u);
			}
			} catch (Exception e) {
			// TODO: handle exception
			e.getMessage();
		}
		return aa;
	}
	
	@Override
    public List<BeanModelMasterBb> insertMasterBB(
                BeanModelMasterBb beanModelMasterbb, String codeMaster,
                String crud) {
          // TODO Auto-generated method stub
         
          if (codeMaster.equals("PEMBANGKIT")){
                MasterAllMembers bb = new MasterAllMembers();
                bb.setNama_pembangkit(beanModelMasterbb.getNama_pembangkit());
                bb.setNama_pic(beanModelMasterbb.getNama_pic());
                bb.setAlamat(beanModelMasterbb.getAlamat());
                bb.setKepemilikan(beanModelMasterbb.getKepemilikan());
                bb.setLatitude(beanModelMasterbb.getLatitude());
                bb.setLongitude(beanModelMasterbb.getLongitude());
                bb.setWilayah(beanModelMasterbb.getWilayah());
            bb.setJenis_pembangkit(beanModelMasterbb.getJenis_pembangkit());
            bb.setTelp(beanModelMasterbb.getTelp());
            bb.setDaya_terpasang(beanModelMasterbb.getDaya_terpasang());
            bb.setSfc(beanModelMasterbb.getSfc());
            bb.setCapacity_factor(beanModelMasterbb.getCapacity_factor());
            bb.setHeat_rate(beanModelMasterbb.getHeat_rate());
            if (crud.equals("CREATE")) {
                bb.setCreateby(beanModelMasterbb.getCreateby());
            }else {
                bb.setId_pltu(Integer.parseInt(beanModelMasterbb.getId_pltu()));
                bb.setUpdateby(beanModelMasterbb.getUpdateby());
            }
            bb.setApp_access("WEB");
           
                bbService.saveMasterKit(bb,codeMaster,crud);
          }else if (codeMaster.equals("PEMASOK")){
                MasterAllMembers bb = new MasterAllMembers();
                bb.setPemasok(beanModelMasterbb.getPemasok());
                bb.setAlamat(beanModelMasterbb.getAlamat());
                bb.setPic_presdir(beanModelMasterbb.getPic_presdir());
                bb.setPic_presdir_hp(beanModelMasterbb.getPic_presdir_hp());
                bb.setPic_dir_marketing(beanModelMasterbb.getPic_dir_marketing());
                bb.setPic_dir_marketing_hp(beanModelMasterbb.getPic_dir_marketing_hp());
                bb.setPic_man_opr(beanModelMasterbb.getPic_man_opr());
                bb.setPic_man_opr_hp(beanModelMasterbb.getPic_man_opr_hp());
                bb.setStatus_pemasok(beanModelMasterbb.getStatus_pemasok());
                bb.setNama_tambang(beanModelMasterbb.getNama_tambang());
                bb.setProduksi(beanModelMasterbb.getProduksi());
                bb.setLoading_port(beanModelMasterbb.getLoading_port());
                bb.setFasilitas_loading(beanModelMasterbb.getFasilitas_loading());
                bb.setJarak_hauling(beanModelMasterbb.getJarak_hauling());
                bb.setFlag_blacklist(beanModelMasterbb.getFlag_blacklist());
                bb.setStatus_aktif(beanModelMasterbb.getStatus_aktif());
                bb.setKeterangan(beanModelMasterbb.getKeterangan());
                bb.setId_pusat(Integer.parseInt(beanModelMasterbb.getId_pusat()));
                bb.setStatus(beanModelMasterbb.getStatus());
                bb.setTelp(beanModelMasterbb.getTelp());
                bb.setFax(beanModelMasterbb.getFax());
                bb.setEmail(beanModelMasterbb.getEmail());
            if (crud.equals("CREATE")) {
                bb.setCreateby(beanModelMasterbb.getCreateby());
            }else {
                bb.setId_pemasok(Integer.parseInt(beanModelMasterbb.getId_pemasok()));
                bb.setUpdateby(beanModelMasterbb.getUpdateby());
            }
            bb.setApp_access("WEB");
           
                bbService.saveMasterKit(bb,codeMaster,crud);
          }else if (codeMaster.equals("TRANSPORTIR")){
                System.out.println("masuk transportir");
                MasterAllMembers bb = new MasterAllMembers();
                bb.setNama_transportir(beanModelMasterbb.getNama_transportir());
                bb.setAlamat(beanModelMasterbb.getAlamat());
                bb.setTelp(beanModelMasterbb.getTelp());
                bb.setPic(beanModelMasterbb.getPic());
                bb.setNama_transport(beanModelMasterbb.getNama_transport());
                bb.setJenis_transport(beanModelMasterbb.getJenis_transport());
                bb.setKode_transport(beanModelMasterbb.getKode_transport());
                bb.setJumlah_kapal(beanModelMasterbb.getJumlah_kapal());
                bb.setSpec_kapal(beanModelMasterbb.getSpec_kapal());
               
                if (crud.equals("CREATE")) {
                bb.setCreateby(beanModelMasterbb.getCreateby());
            }else {
                  bb.setId_transportir(Integer.parseInt(beanModelMasterbb.getId_transportir()));
                  bb.setUpdateby(beanModelMasterbb.getUpdateby());
            }
            bb.setApp_access("WEB");
            bbService.saveMasterKit(bb,codeMaster,crud);
          }else if (codeMaster.equals("SURVEYOR")){
                System.out.println("masuk SURVEYOR");
                MasterAllMembers bb = new MasterAllMembers();
                bb.setNama_surveyor(beanModelMasterbb.getNama_surveyor());
                bb.setNo_kerjasama(beanModelMasterbb.getNo_kerjasama());
                bb.setTanggal(beanModelMasterbb.getTanggal());
                System.out.println("tgl di service: " + beanModelMasterbb.getTanggal());
                bb.setTelp(beanModelMasterbb.getTelp());
                System.out.println("tlp di service: " + beanModelMasterbb.getTelp());
                bb.setAlamat(beanModelMasterbb.getAlamat());
                bb.setPic(beanModelMasterbb.getPic());
                bb.setKeterangan(beanModelMasterbb.getKeterangan());
                bb.setNo_kontrak(beanModelMasterbb.getNo_kontrak());
                if (crud.equals("CREATE")) {
                bb.setCreateby(beanModelMasterbb.getCreateby());
            }else {
                bb.setId_surveyor(Integer.parseInt(beanModelMasterbb.getId_surveyor()));
                bb.setUpdateby(beanModelMasterbb.getUpdateby());
            }
            bb.setApp_access("WEB");
           
                bbService.saveMasterKit(bb,codeMaster,crud);
          }
         
         
          return null;
    }
	
	@Override
    public List<Map> getListPengendalianBb(String kode, Map map) {
		
	return bbService.getListPengendalianBb(kode, map); 
  }
	
	@Override
	public List<Map> insertBbPengendalian(String kode, Map map) {
		// TODO Auto-generated method stub
		return bbService.insertBbPengendalian(kode, map);
	}

	@Override
	public List<Map> getListpltu_rakor(String kode, Map map) {
		// TODO Auto-generated method stub
		return bbService.getListpltu_rakor(kode, map);
	}

	@Override
	public List<Map> getListpemasok_rakor(String kode, Map map) {
		// TODO Auto-generated method stub
		return bbService.getListpemasok_rakor(kode, map);
	}

	@Override
	public List<Map> setRelationRakor(String kode, Map map) {
		// TODO Auto-generated method stub
		return bbService.setRelationRakor(kode, map);
	}


}
